home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CTRACE2_ / CLOGLIST.C next >
Text File  |  1990-12-10  |  2KB  |  82 lines

  1. /*****     
  2.     from CTRACE: A MESSAGE LOGGING CLASS
  3.     by William D. Cramer in Dr. Dobbs Journal #170, p. 44-55, 116-120.
  4. *****/
  5.  
  6. /** CLogList.c -- Methods for a LogList object. **/
  7.  
  8. #include "CLogList.h"        /* definitions for LogList class */
  9.     
  10. /** ILogList -- Initializes a LogList for the indicated number of entries. **/
  11. void CLogList::ILogList
  12.     (
  13.     short records        /* maximum number of entries */
  14.     )
  15. {
  16. CList::IList ();
  17. maxRec = records;        
  18. }
  19.  
  20. /** Dispose -- Frees all records (and their handles) in the list **/
  21. void CLogList::Dispose (void)
  22. {
  23. short 
  24.     i;                /* loop counter */
  25. Handle 
  26.     record;             /* handle to list record */
  27. while (GetNumItems() > 0) 
  28.     {
  29.     record = (Handle)FirstItem();
  30.     Remove ((CObject*)record);
  31.     DisposHandle (record);
  32.     }
  33. }
  34.  
  35. /** AddString -- Adds a string to LogList. **/ 
  36. void CLogList::AddString 
  37.     (
  38.     char *theString     /* pointer to null-terminated string */
  39.     )
  40. {
  41. Handle    
  42.     record;         /* handle for a list entry */
  43. if (strlen(theString)+1 < MAX_LOGREC_CHAR)
  44.     {
  45.     record = NewHandle (strlen(theString)+1);
  46.     strcpy (*record, theString);
  47.     }
  48. else
  49.     {
  50.     record = NewHandle (MAX_LOGREC_CHAR);
  51.     strncpy (*record, theString, MAX_LOGREC_CHAR);
  52.     *record[MAX_LOGREC_CHAR-1] = NULL;
  53.     }
  54. Append ((CObject*)record);
  55. if (GetNumItems () > maxRec)
  56.     {
  57.     record = (Handle)FirstItem ();    
  58.     Remove ((CObject*)record);
  59.     DisposHandle (record);
  60.     }
  61. }
  62.  
  63. /** GetString -- Grabs requested entry and copies it to user's buffer. **/
  64. void CLogList::GetString 
  65.     (
  66.     short which,        /* record number to return */
  67.     char *theString     /* point to destination buffer */
  68.     )
  69. {
  70. Handle 
  71.     record;         /* handle for a list entry */
  72. if ( (record=(Handle)NthItem(which)) != NULL)
  73.     strcpy (theString, *record);
  74. else
  75.     theString[0] = 0;
  76. }
  77.  
  78. /** GetMaxRecordCount -- Returns max.number of records available in LogList **/
  79. short CLogList::GetMaxRecordCount (void)
  80. {
  81. return (maxRec);
  82. }